<template>
    <div>
        <div class="container">
            <!-- 头部 -->
            <div class="nav">
                <div class="nav_wrap">
                    <div class="quit" @click="$router.back()"></div>
                    <span>搜索</span>
                    <div class="nav_icon">
                        <router-link tag="a" to="/shelf"></router-link>
                        <i v-show="!isTop" @click="topShow"></i>
                        <i class="topnav" v-show="isTop" @click="topShow"></i>
                    </div>
                </div>
            </div>
            <div class="wrap" v-show="isTop" @click.self="topShow">
                <div class="subnav">
                    <ul>
                        <router-link tag="li" to="/">
                            <img src="../assets/images/tp_1.png" alt="">
                            <span>首页</span>
                        </router-link>
                        <router-link tag="li" to="/library">
                            <img src="../assets/images/tp_02.png" alt="">
                            <span>书库</span>
                        </router-link>
                        <router-link tag="li" to="/shelf">
                            <img src="../assets/images/tp_03.png" alt="">
                            <span>书架</span>
                        </router-link>
                        <router-link tag="li" to="/user">
                            <img src="../assets/images/tp_04.png" alt="">
                            <span>账户</span>
                        </router-link>
                        <router-link tag="li" to="/pay">
                            <img src="../assets/images/tp_05.png" alt="">
                            <span>充值</span>
                        </router-link>
                        <router-link tag="li" to="/search">
                            <img src="../assets/images/tp_06.png" alt="">
                            <span>搜索</span>
                        </router-link>
                    </ul>
                </div>
            
            </div>
            <!-- 搜索框 -->
            <router-link tag="div" to="/search" class="search bor_bot">
                <div class="search_wrap">
                    <input type="text" v-model="val">
                    <button @click="search"></button>
                </div>
            </router-link>
            <!-- 最近搜索 -->
            <!-- <div class="his_book bor_bot">
                <h2>最近搜索</h2>
                <ul>
                    <li v-for="(item,index) in comment" :key="index">
                        {{item}}
                    </li>
                </ul>
            </div> -->
            <!-- 书单 -->
            <div class="list_books bor_bot" v-if="len">
                <div class="books_cont" >
                    <ul>
                        <router-link tag="li" :to="{ path: '/about', query: { userId: item.id } }" v-for="(item,index) in booksData"
                            :key="index">
                            <div class="img">
                                <img :src="item.iconUrl" alt="">
                            </div>
                            <div class="intro">
                                <div class="in_tit">
                                    {{item.title}}
                                </div>
                                <p>
                                    {{ item.description }}
                                </p>
                                <div class="in_foot">
                                    <div class="state">
                                        <span>{{ item.bookStatus ? '完结' : '连载'}}</span>
                                    </div>
                                    <div class="book_type">
                                        <span class="book_num">{{ item.showTotalCount }}</span>
                                        <span>{{ item.category }}</span>
                                    </div>
                                </div>
                            </div>
                        </router-link>
                    </ul>
                </div>
            </div>
            <!-- 没有数据 -->
            <div class="emtry" v-else>
                <div class="txt">
                    <span>哇, 居然没有搜到, 试试别的关键字</span>
                </div>
            </div>
            
            <!-- 搜索框 -->
            <router-link tag="div" to="/search" class="search">
                <div class="search_wrap">
                    <input type="text">
                    <button></button>
                </div>
            </router-link>
            <!-- 页脚信息 -->
            <div class="footer">
                <div class="foot_tit">
                    <ul>
                        <li>
                            <a href="javascript:;">首页</a>
                        </li>
                        <li>
                            <a href="javascript:;">书库</a>
                        </li>
                        <li>
                            <a href="javascript:;">书架</a>
                        </li>
                        <li>
                            <a href="javascript:;">账户</a>
                        </li>
                        <li>
                            <a href="javascript:;">客户端</a>
                        </li>
                    </ul>
                </div>
                <div class="foot_cont">
                    <div class="foot_info">
                        <p>客服QQ群：326738643</p>
                        <p>客服电话：010-86462015-800</p>
                        <p>©2020北京爱书客科技有限公司</p>
                        <p>京ICP备13037522号</p>
                    </div>
                    <div class="info_img">
                        <img src="../assets/images/ledu.png" alt="">
                        <span>乐读书城</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { getJsonData } from '../api/home';
export default {
    data() {
        return {
            booksData: null,//书单数据
            len:true,//
            booksCopy: null,//书单数据
            isTop: false,//判断子菜单的展示
            comment:['123','888'],//搜索历史
            val:"",//搜索框内容
        }
    },
    created() {
        getJsonData().then(data => {
            this.booksData = data.data.books;
            this.booksCopy = data.data.books;
        })
    },
    methods:{
        topShow() {
            this.isTop = !this.isTop
        },
        search(){
            let val = this.val;
            if(val == ""){
                this.$toast("内容不能为空");
                return
            }
            this.comment.push(val);
            let ind = [];
            this.booksCopy.forEach((item,index) => {
                if (item.title.indexOf(val) != -1){
                    ind.push(index);
                    console.log(item);
                }
            })
            this.booksData = [];
            if(ind.length != 0){
                this.len = true;
                for(let i = 0; i < ind.length; i++){
                    this.booksData.push(this.booksCopy[ind[i]]);
                }
            } else {
                this.len = false;
            }
            
            
        }
    }
}
</script>

<style lang="scss" scoped>
.nav {
    background-color: #fff;

    .nav_wrap {
        padding: 0 14px;
        border-bottom: 1px solid #e0e0e0;
        display: flex;

        .quit {
            width: 10px;
            height: 45px;
            background-image: url('../assets/images/quit.png');
            background-repeat: no-repeat;
            background-size: 100%;
            background-position: center;
        }

        span {
            color: #333;
            font-size: 16px;
            display: block;
            text-align: center;
            line-height: 45px;
            width: 54%;
            padding-left: 70px;
        }

        .nav_icon {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 80px;

            a {
                display: block;
                width: 25px;
                height: 22px;
                background-image: url('../assets/images/book_ico1.png');
                background-repeat: no-repeat;
                background-size: 100%;
                background-position: center;
            }

            i {
                display: block;
                width: 20px;
                height: 20px;
                background-image: url('../assets/images/bookMore_ico1.png');
                background-size: 100%;
                background-position: center;

            }

            .topnav {
                background-image: url('../assets/images/tp_close.png');
            }
        }
    }
}

.wrap {
    position: fixed;
    top: 45px;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, .8);

    .subnav {
        width: 100%;
        background-color: #fff;
        padding-bottom: 18px;

        ul {
            display: flex;
            flex-wrap: wrap;

            li {
                width: 25%;
                text-align: center;
                padding-top: 20px;

                img {
                    width: 40px;
                    height: 40px;
                    margin: 0 auto 8px auto;
                }

                span {
                    font-size: 13px;
                    color: #666;
                }
            }
        }
    }

}
.his_book {
    padding: 18px 14.5px;
    h2 {
        font-size: 16px;
        color: #333;
        display: flex;
        justify-content: space-between;
        &::after {
            content: "";
            display: inline-block;
            vertical-align: middle;
            width: 16px;
            height: 16px;
            background-image: url('../assets/images/del_icon.png');
            background-size: 100%;
        }
    }
    ul{
        display: flex;
        padding-top: 20px;
        flex-wrap: wrap;
        li{
            color: #333;
            font-size: 11px;
            border: 1px solid #c9c9c9;
            padding: 6px 10px;
            border-radius: 15px;
            margin-right: 16px;
        }
    }
}

.bor_bot {
    border-bottom: 10px solid #eaeaea;
}
.list_books {
    padding: 0 14px;

    .books_cont {
        .sort_uls {
            padding-bottom: 0px;
        }

        ul {
            padding-bottom: 28px;

            li {
                display: flex;
                padding-top: 24px;

                .img {
                    flex: 1;

                    img {
                        width: 100px;
                        height: 140px;
                    }
                }

                .intro {
                    flex: 2;
                    padding-left: 5px;

                    .in_tit {
                        height: 47px;
                        color: #666;
                        font-size: 18px;
                    }

                    &>p {
                        height: 47px;
                        line-height: 22px;
                        font-size: 13px;
                        color: #999;
                        text-indent: 26px;
                        overflow: hidden;
                    }
                }

                .in_foot {
                    display: flex;
                    justify-content: space-between;
                    padding-top: 29px;

                    span {
                        border: 1px solid #fff;
                        display: block;
                        font-size: 12px;
                        height: 10px;
                        line-height: 10px;
                        padding: 2px 3.5px;
                    }

                    .state {
                        span {
                            border-color: #ea4136;
                            color: #ea4136;
                        }
                    }

                    .book_type {
                        display: flex;

                        .book_num {
                            border-color: #f39800;
                            color: #f39800;
                            margin-right: 6px;
                        }

                        span {
                            border-color: #706262;
                            color: #706262;
                        }
                    }
                }
            }
        }
    }
        

}
.emtry {
    min-height: 282px;
    background-color: #f1f1f1;

    .txt {
        background-image: url('../assets/images/noSearch.png');
        background-repeat: no-repeat;
        background-position: center;
        background-size: 150px 130px;
        height: 187px;
        text-align: center;

        span {
            vertical-align: -167px;
            color: #999;
            font-size: 14px;
        }
    }
}
.search {
    padding: 10px 14px;

    .search_wrap {
        display: flex;
        padding: 4px 0 4px 17px;
        border: 1px solid #dbdbdb;
        height: 32px;
        border-radius: 20px;
        overflow: hidden;

        &>input {
            border: 0px;
            outline: none;
            flex: 6;
            color: #999;
        }

        &>button {
            flex: 1;
            background-image: url('../assets/images/searchBar.png');
            background-repeat: no-repeat;
            border: 0px;
            background-color: #fff;
            position: relative;
            border-left: 1px solid #dbdbdb;
            background-size: 18px;
            background-position: center;
        }
    }
}

.footer {
    padding: 16px 0px 32px 0px;
    background-color: #1c1a1a;

    .foot_tit {
        padding-bottom: 15px;

        ul {
            display: flex;

            li {
                flex: 1;

                a {
                    display: block;
                    font-size: 16px;
                    color: #b6b6b6;
                    text-align: center;
                    border-right: 1px solid #999999;

                }

                &:last-of-type {
                    a {
                        border: 0px;
                    }
                }
            }
        }
    }

    .foot_cont {
        display: flex;
        justify-content: space-between;
        padding: 0 16px;

        .foot_info {
            p {
                color: #b6b6b6;
                font-size: 12px;
                line-height: 28px;
            }
        }

        .info_img {
            img {
                width: 98px;
                height: 98px;
            }

            span {
                font-size: 12px;
                display: block;
                text-align: center;
                color: #b6b6b6;
                padding-top: 3px;
            }
        }
    }
}
</style>